﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Farmacia.BussinessLogic;
using Microsoft.Practices.Unity;

namespace Farmacia.net.Compras.Proveedor
{
    public partial class frmBuscarProveedor :BasePage<frmBuscarProveedor> //System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var msg = Request.QueryString["msg"];

            if (msg != null)
            {
                lblMensaje.Text = msg.ToString();
            }
            txtRuc.Focus();
        }

        [Dependency]
        public iProveedorBL proveedorBL { get; set; }

        protected void odsProveedor_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = proveedorBL;
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Eliminar")
            {
                try
                {
                    var row = e.CommandArgument;

                    GridView1.SelectedIndex = Int32.Parse(row.ToString());  //Int32.Parse(row.ToString());

                    var key = GridView1.SelectedDataKey.Value;

                    proveedorBL.DeleteProveedor(Int32.Parse(key.ToString()));
                    Response.Redirect("frmBuscarProveedor.aspx");
                }
                catch (Exception ex)
                {
                    lblMensaje.Text = ex.Message;
                }
            }
        }

        protected void odsProveedor_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            if (e.Exception != null)
            {

                lblMensaje.Text = e.Exception.Message;
            }
        }
    }
}